#include "fifo.h"

VOID Fifo8Init(PFIFO8 pFifo, DWORD dwSize, PBYTE pbBuffer){
	pFifo->pbBuffer = pbBuffer;
    pFifo->dwSize = dwSize;
    pFifo->dwWrite = 0;
    pFifo->dwRead = 0;
    pFifo->dwFree = dwSize;
}

STATUS Fifo8Put(PFIFO8 pFifo, BYTE bData){
	if(pFifo->dwFree == 0)
        return STATUS_NOMEM;
    pFifo->pbBuffer[pFifo->dwWrite++] = bData;
    if(pFifo->dwWrite == pFifo->dwSize)
        pFifo->dwWrite = 0;
    pFifo->dwFree--;
    return STATUS_NOERR;
}

STATUS Fifo8Get(PFIFO8 pFifo, PBYTE pbData){
	if(pFifo->dwFree == pFifo->dwSize)
        return STATUS_EMPTY;
    *pbData = pFifo->pbBuffer[pFifo->dwRead++];
    if(pFifo->dwRead == pFifo->dwSize)
        pFifo->dwRead = 0;
    pFifo->dwFree++;
    return STATUS_NOERR;
}

DWORD Fifo8Status(PFIFO8 pFifo){
    return pFifo->dwFree;
}
